package models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import play.data.validation.Required;
import play.db.jpa.GenericModel;

@Entity
@Table(name = "survey")
public class Survey extends GenericModel {

    @Id
    @Column(name = "survey_id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long surveyId;

    @Required
    @Column(name = "date")
    public Date surveyDate;

    @Required
    @Column(name = "difficulty_degree")
    public Integer difficultyDegree;

    @Required
    @Column(name = "insufficiency_degree")
    public Integer insufficiencyDegree;

    @ManyToOne(targetEntity = User.class, optional = false)
    @JoinColumn(name = "doctor_id", nullable = false)
    public User doctor;

    @ManyToOne(targetEntity = MedicineCard.class, optional = false)
    @JoinColumn(name = "medicine_card_id", nullable = false)
    public MedicineCard medicineCard;

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = super.hashCode();
	result = prime
		* result
		+ ((difficultyDegree == null) ? 0 : difficultyDegree.hashCode());
	result = prime * result + ((doctor == null) ? 0 : doctor.hashCode());
	result = prime
		* result
		+ ((insufficiencyDegree == null) ? 0 : insufficiencyDegree
			.hashCode());
	result = prime * result
		+ ((medicineCard == null) ? 0 : medicineCard.hashCode());
	result = prime * result
		+ ((surveyDate == null) ? 0 : surveyDate.hashCode());
	result = prime * result
		+ ((surveyId == null) ? 0 : surveyId.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (!super.equals(obj))
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Survey other = (Survey) obj;
	if (difficultyDegree == null) {
	    if (other.difficultyDegree != null)
		return false;
	} else if (!difficultyDegree.equals(other.difficultyDegree))
	    return false;
	if (doctor == null) {
	    if (other.doctor != null)
		return false;
	} else if (!doctor.equals(other.doctor))
	    return false;
	if (insufficiencyDegree == null) {
	    if (other.insufficiencyDegree != null)
		return false;
	} else if (!insufficiencyDegree.equals(other.insufficiencyDegree))
	    return false;
	if (medicineCard == null) {
	    if (other.medicineCard != null)
		return false;
	} else if (!medicineCard.equals(other.medicineCard))
	    return false;
	if (surveyDate == null) {
	    if (other.surveyDate != null)
		return false;
	} else if (!surveyDate.equals(other.surveyDate))
	    return false;
	if (surveyId == null) {
	    if (other.surveyId != null)
		return false;
	} else if (!surveyId.equals(other.surveyId))
	    return false;
	return true;
    }

    @Override
    public String toString() {
	return "Survey [surveyId=" + surveyId + ", surveyDate=" + surveyDate
		+ ", difficultyDegree=" + difficultyDegree
		+ ", insufficiencyDegree=" + insufficiencyDegree + ", doctor="
		+ doctor + ", medicineCard=" + medicineCard + "]";
    }

}
